package cn.redsoft.wechatapi.msg.req.event;

import cn.redsoft.wechatapi.msg.req.RequestMsg;
import cn.redsoft.wechatapi.msg.req.RequestMsgType;

import com.thoughtworks.xstream.annotations.XStreamAlias;

public abstract class EventRequestMsg extends RequestMsg {

	@XStreamAlias("Event")
	protected Event event;

	public EventRequestMsg() {
		this.msgType = RequestMsgType.EVENT;
	}

	public EventRequestMsg(String toUserName, String fromUserName,
			Long createTime, long msgId) {
		super(toUserName, fromUserName, createTime, null, msgId);
		this.msgType = RequestMsgType.EVENT;
	}

	@Override
	public RequestMsgType getMsgType() {
		return RequestMsgType.EVENT;
	}

	public Event getEvent() {
		return event;
	}

	public void setEvent(Event event) {
		this.event = event;
	}

	public static enum Event {
		SUBSCRIBE("subscribe")// 订阅
		, UNSUBSCRIBE("unsubscribe")// 取消订阅
		, CLICK("CLICK") //
		, VIEW("VIEW")//
		, LOCATION("LOCATION")//
		, QR_CODE_SCANNING_UNSUBSCRIBE("subscribe")//
		, QR_CODE_SCANNING_SUBSCRIBED("SCAN")//
		;
		private String value;

		private Event(String v) {
			this.value = v;
		}

		public String getValue() {
			return value;
		}

		public static Event toEnum(String str) {
			try {
				return Enum.valueOf(Event.class, str);
			} catch (Exception ex) {
				for (Event period : Event.values()) {
					if (period.getValue().equalsIgnoreCase(str)) {
						return period;
					}
				}
				throw new IllegalArgumentException("Cannot convert <" + str
						+ "> to TimePeriod enum");
			}
		}
	}
}
